/**
 * 
 */
package com.alstudio.view.listener;

import android.view.View;
import android.view.View.OnClickListener;

/**
 * @author alonso lee
 * 
 */
public abstract class AlViewClickManager implements OnClickListener {

	private long startTime;
	private long lastInvokeTime;

	public abstract void onALViewClick(View v);

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		invokeViewClick(v);
	}

	private synchronized void invokeViewClick(View v) {
		startTime = System.currentTimeMillis();
		if (lastInvokeTime == 0) {
			onALViewClick(v);
			lastInvokeTime = startTime;
		} else {
			if (startTime - lastInvokeTime > 500) {
				onALViewClick(v);
				lastInvokeTime = startTime;
			}
		}
	}

}
